home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / listings / v_13_09 / letters / vects.c < prev   
Text File  |  1995-07-17  |  2KB  |  101 lines

  1. /* Listing 2: d2.asm */
  2.  
  3. /********User modified function**
  4. *********for getvect))**********/
  5. void interrupt(*getv(int intnum))
  6.   (__CPPARGS)
  7. {
  8. long old=0;
  9.  
  10. asm{
  11.     CLI;   /* Disable intrpts */
  12.     PUSH AX;     /* Save regs */
  13.     PUSH BX
  14.     PUSH DS
  15.  
  16. ;   /* Int number passed by
  17. ;      function call          */
  18.  
  19.     MOV BX, intnum;
  20.     SHL BX,2;
  21.  
  22. ;   /* Zero the data segment to
  23. ;      point to vector table  */
  24.  
  25.     XOR AX,AX
  26.     MOV DS,AX
  27.     MOV AX,[BX]
  28.  
  29. ;   /* Get low word of vector */
  30.  
  31.     MOV WORDPTR old,AX
  32.     MOV AX,[BX+2]
  33.  
  34. ;   /* Get high wrd of vector */
  35.  
  36.     MOV WORDPTR old+2,AX
  37.     POP DS; /*  Restore regs  */
  38.     POP BX
  39.     POP AX
  40.     STI;    /* Enable intrpts */
  41.     }
  42. (long) oldhandler 
  43.    = old:  /* Klunky, but it 
  44.               works and avoids 
  45.               type mismatches */
  46.  
  47. return oldhandler;
  48. }
  49. /***User modified function******
  50. ****for setvect() *************/
  51. void 
  52. setv(int, 
  53.      void interrupt(*3)_CPPARGS))
  54. {
  55. asm{
  56.     CLI
  57.     PUSH AX; /* Save regs */
  58.     PUSH BX; /* on stack
  59.     PUSH DS
  60.     PUSH BP
  61.  
  62. ;   /* The zero segment is used
  63. ;      for the interrupt vector
  64. ;      table                   */
  65.  
  66.     XOR AX,AX
  67.     MOV DS,AX
  68.  
  69. ;   /* Get the interrupt number
  70. ;      from the calling program
  71. ;      into BX(X4)             */
  72.  
  73.     MOV BX,[BP+04]
  74.     SHL BX,2
  75.  
  76. ;   /* Use it to place the low
  77. ;      word                    */
  78.     MOV AX,[BP+06]
  79.     MOV [BX],AX
  80.  
  81. ;   /* then place the high wrd */
  82.     
  83.     MOV AX,[BP+08]
  84.  
  85. ;   /* (Turbo debugger 4.02
  86. ;       doesn't show this
  87. ;       happening, even with
  88. ;       unmodified Borland
  89. ;       example                */ 
  90.     MOV [BX+2],AX
  91.     POP BP
  92.     POP DS
  93.     POP BX; /* Restore regs    */
  94.     POP AX 
  95.     STI; /* Enable interrupts. */
  96.     }
  97. return
  98. }
  99.  
  100.  
  101.